package com.yunkeji.admin.controller.pay;

import cn.dev33.satoken.annotation.SaCheckPermission;

import com.yunkeji.common.annotation.Log;
import com.yunkeji.common.annotation.RepeatSubmit;
import com.yunkeji.common.core.controller.BaseController;
import com.yunkeji.common.core.domain.PageQuery;
import com.yunkeji.common.core.domain.R;
import com.yunkeji.common.core.page.TableDataInfo;
import com.yunkeji.common.core.validate.AddGroup;
import com.yunkeji.common.core.validate.EditGroup;
import com.yunkeji.common.enums.BusinessType;
import com.yunkeji.common.utils.poi.ExcelUtil;
import com.yunkeji.dao.vo.PayWithdrawVo;
import com.yunkeji.system.domain.bo.PayWithdrawBo;
import com.yunkeji.system.domain.bo.PayWithdrawCheckBo;
import com.yunkeji.system.service.IPayWithdrawService;

import lombok.RequiredArgsConstructor;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * 支付-提现
 *
 * @author zhang
 * @date 2024-07-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/payWithdraw")
public class PayWithdrawController extends BaseController {

    private final IPayWithdrawService iPayWithdrawService;

    /** 审核通过 */
    @SaCheckPermission("system:payWithdraw:pass")
    @Log(title = "支付-审核通过", businessType = BusinessType.INSERT)
    @PostMapping("/pass")
    public R<Void> pass(@RequestBody PayWithdrawCheckBo bo) {
        iPayWithdrawService.pass(bo);
        return R.ok();
    }

    /** 审核拒绝 */
    @SaCheckPermission("system:payWithdraw:refuse")
    @Log(title = "支付-审核拒绝", businessType = BusinessType.INSERT)
    @PostMapping("/refuse")
    public R<Void> refuse(@RequestBody PayWithdrawCheckBo bo) {
        iPayWithdrawService.refuse(bo);
        return R.ok();
    }

    /** 查询支付-提现列表 */
    @SaCheckPermission("system:payWithdraw:list")
    @GetMapping("/list")
    public TableDataInfo<PayWithdrawVo> list(PayWithdrawBo bo, PageQuery pageQuery) {
        return iPayWithdrawService.queryPageList(bo, pageQuery);
    }

    /** 导出支付-提现列表 */
    @SaCheckPermission("system:payWithdraw:export")
    @Log(title = "支付-提现", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PayWithdrawBo bo, HttpServletResponse response, PageQuery pageQuery) {
        TableDataInfo<PayWithdrawVo> dataInfo = iPayWithdrawService.queryPageList(bo, pageQuery);
        ExcelUtil.exportExcel(dataInfo.getRows(), "支付-提现", PayWithdrawVo.class, response);
    }

    /**
     * 获取支付-提现详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:payWithdraw:query")
    @GetMapping("/{id}")
    public R<PayWithdrawVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(iPayWithdrawService.queryById(id));
    }

    /** 新增支付-提现 */
    @SaCheckPermission("system:payWithdraw:add")
    @Log(title = "支付-提现", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PayWithdrawBo bo) {
        return toAjax(iPayWithdrawService.insertByBo(bo));
    }

    /** 修改支付-提现 */
    @SaCheckPermission("system:payWithdraw:edit")
    @Log(title = "支付-提现", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PayWithdrawBo bo) {
        return toAjax(iPayWithdrawService.updateByBo(bo));
    }

    /**
     * 删除支付-提现
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:payWithdraw:remove")
    @Log(title = "支付-提现", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iPayWithdrawService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
